<template>
  <div style="height: 70%;margin-top: 15%;">
    <!-- <div id="yichangChart" style="width: 90%;height: 100%;"></div>
    -->
    <div v-for="item in dataa" style="display:flex;justify-content: space-between; margin: 7% 5%;">
    {{item.name}}
      <el-progress :text-inside="true" :stroke-width="18" :percentage="item.value" status="success" color="#14CFF299" style="width: 200px;"></el-progress>
    </div>
  </div>
</template>
<script>
import echarts from "echarts";
import homeService from "../../../../services/homeService";

export default {

  data(){
    return {
      dataa: []
    }
  },

  mounted() {
    this.initData();
  },

  methods: {
    drawYiChangChart() {
      // 基于准备好的dom，初始化echarts实例
      let yichangChart = echarts.init(
        document.getElementById("yichangChart"),
        "dark"
      );
      // window.onresize = yichangChart.resize;
      window.addEventListener("resize", () => {
        yichangChart.resize();
      });
      // 绘制图表
      let option = {
        backgroundColor: "",
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow" // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        legend: {
          data: ["设备总数", "异常数量"],
          width: 50
        },
        grid: {
          // left: "3%",
          // right: "4%",
          // bottom: "3%",
          containLabel: true
          // x: 50
        },
        xAxis: {
          show: false,
          axisLine: {
            show: false
          },
          type: "value"
        },
        yAxis: {
          show: true,
          axisLine: {
            show: false
          },
          axisLabel: {
            margin: 8
          },
          type: "category",
          data: this.yAxis
        },
        series: [
          {
            name: "异常数量",
            type: "bar",
            stack: "总量",
            itemStyle: {
              normal: { color: "#15F1C955", label: { show: true } }
            },
            label: {
              normal: {
                color: "#aaa",
                // show: true,
                position: "insideTop"
              }
            },
            data: this.fault
          },
          {
            name: "设备总数",
            type: "bar",
            stack: "总量",
            itemStyle: {
              normal: { color: "#3358A9aa", label: { show: true } }
            },
            label: {
              normal: {
                show: true,
                position: "insideRight"
              }
            },
            data: this.total
          }
        ]
      };
      yichangChart.setOption(option);
    },

    initData() {
      let _this = this;

      //初始化
      homeService.zixitongyichang().then(res => {
        if (res.code == 0) {
          _this.dataa = [];
          res.data.map(item => {
            _this.dataa.push({
              name: item.facilityName,
              value: parseInt(((item.count - item.faultCount) / item.count) * 100)
            });
          });
          // _this.drawYiChangChart();
        }
      });

      // homeService.zixitongyichang().then(res => {
      //   if (res.code == 0) {
      //     _this.yAxis = [];
      //     _this.total = [];
      //     _this.fault = [];
      //     res.data.map(item => {
      //       _this.yAxis.push(item.facilityName);
      //       _this.total.push(item.count);
      //       _this.fault.push(item.faultCount);
      //     });
      //     _this.drawYiChangChart();
      //   }
      // });
    }
  }
};
</script>
<style lang="scss">
.el-progress-bar__outer{
  background-color: #3358A999;
  
}
</style>
